<?php
namespace app\index\controller;

use app\index\controller\FrontBase;
use mailer\tp5\Mailer;
use think\Config;
use think\Request;
use think\Validate;

class Index extends FrontBase
{
    public function index(){
        return view('',$this->param);
    }

    public function messages(){
        return view('',$this->param);
    }

    public function permission(){
        $permission = ["admin/menu/delete","admin/menu/update","admin/menu/create","admin/menu/edit","admin/menu/add","admin/menu/index",'admin/user/delete',"admin/user/update","admin/user/edit","admin/user/index","admin/user/create","admin/user/add","admin/upload/upload","admin/role/update","admin/role/delete","admin/role/create","admin/role/edit","admin/role/add","admin/role/index","admin/permission/update","admin/permission/index","admin/index/index","admin/permission/add","admin/permission/edit","admin/permission/create","admin/index/main","admin/permission/delete"];
        $permission = serialize($permission);
        return $permission;
    }

    public function sitemap(){
        return view('',$this->param);
    }

    public function test(){

        echo '1234';
    }

    public function privates(){
        $privates = <<<PRI
<h1>Private Policy</h1>
This privacy policy describes how we handle your personal information. By using www.horseen.com (the "Site") you consent to the storage, processing, transfer and disclosure of your personal information as described in this privacy policy.

<h5>Collection</h5>
<p>
You may browse this Site without providing any personal information about yourself. However, to receive notifications, updates or request additional information about www.horseen.com or this Site, we may collect the following information:
name, contact information, email address, company and user ID;
correspondence sent to or from us;
any additional information you choose to provide; and other information from your interaction with our Site, services, content and advertising, including computer and connection information, statistics on page views, traffic to and from the Site, ad data, IP address and standard web log information.
If you choose to provide us with personal information, you consent to the transfer and storage of that information on our servers located in the United States.
</p>

<h5>Use</h5>
<p>
We use your personal information to provide you with the services you request, communicate with you, troubleshoot problems, customize your experience, inform you about our services and Site updates and measure interest in our sites and services.
Like many websites, we use "cookies" to enhance your experience and gather information about visitors and visits to our websites. Please refer to the "Do we use 'cookies'?" section below for information about cookies and how we use them.
</p>


<h5>Disclosure</h5>
<p>
We don't sell or rent your personal information to third parties for their marketing purposes without your explicit consent. We may disclose personal information to respond to legal requirements, enforce our policies, respond to claims that a posting or other content violates other's rights, or protect anyone's rights, property, or safety. Such information will be disclosed in accordance with applicable laws and regulations. We may also share personal information with service providers who help with our business operations, and with members of our corporate family, who may provide joint content and services and help detect and prevent potentially illegal acts. Should we plan to merge or be acquired by another business entity, we may share personal information with the other company and will require that the new combined entity follow this privacy policy with respect to your personal information.
</p>

<h5>Access</h5>
<p>
You may access or update the personal information you provided to us at any time by contacting us at www.horseen.com
</p>

<h5>Security</h5>
<p>
We treat information as an asset that must be protected and use lots of tools to protect your personal information against unauthorized access and disclosure. However, as you probably know, third parties may unlawfully intercept or access transmissions or private communications. Therefore, although we work very hard to protect your privacy, we do not promise, and you should not expect that your personal information or private communications will always remain private.
</p>

<h5>General</h5>
<p>
We may update this policy at any time by posting amended terms on this site. All amended terms automatically take effect 30 days after they are initially posted on the site. For questions about this policy, please send email to us.
</p>

PRI;

        return $privates;
    }

    public function sendMail(Request $request){
        if(!$request->isPost()){
            echo json_encode(["state"=>'err','message'=>'Permission denied']);exit;
        }
        $params = $request->param();
        if(isset($params['needemail'])){
            if(!(isset($params['email']) && Validate::is($params['email'],'email'))){
                echo json_encode(["state"=>'err','message'=>'Not fill in the Email or Email address is not correct']);exit;
            }
        }
        if(isset($params['phone']) && empty($params['phone'])){
            echo json_encode(["state"=>'err','message'=>'please provide both your phone number and email,thanks']);exit;
        }


        $text = '';
        foreach($params as $key => $val ){
               $text .= $key.':'.$val."\n";
        }

        $mailer = Mailer::instance();
        $mailer->from('13482021417@163.com', "user")
            ->to('info@shhorse.com')
            //->to('1427047861@qq.com')
            ->subject('来自www.horseen.com的留言')
            ->text($text)
            ->send();
        echo json_encode(['state'=>'ok','message'=>'Succeed to be sent']);exit;

    }

}
